package com.example.tp_1;

import android.app.Activity;
import android.app.AlertDialog;
import android.database.Cursor;
import android.os.Bundle;
import android.support.v4.widget.SimpleCursorAdapter;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.widget.Button;
import android.widget.ListView;

import com.example.sqlite.DM_Society_Boutique;
import com.example.utilitaire.Stat_Boutique;

public class Mon_panier extends Activity implements android.view.View.OnClickListener
{
	
	private DM_Society_Boutique _myDMSociety_Boutique;
	
	private ListView lListView;
	private Cursor _myCursor;
	private SimpleCursorAdapter _lAdapter;

	private Button _precedent;
	private Button _commander;
	
	public void onCreate(Bundle savedInstanceState)
	{
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_mon_panier);
		
	      _precedent.setOnClickListener(this);
	      _commander.setOnClickListener(this);
	      
	     
	      _myDMSociety_Boutique=new DM_Society_Boutique(this);
	      
	      _myCursor= _myDMSociety_Boutique.afficherTout_panier();
	      
	      
	      String[] from={Stat_Boutique.COL_P_REF,Stat_Boutique.COL_P_PRIX,Stat_Boutique.COL_P_QUANTITY};
	      int[] to={R.id.Tp1_monPanier_strocture_textView_reference,R.id.Tp1_monPanier_strocture_textView_prix,R.id.Tp1_monPanier_strocture_textView_quantite};
	      
	       _lAdapter=new SimpleCursorAdapter(this, R.layout.strocture_listview_monpanier, _myCursor, from, to, SimpleCursorAdapter.FLAG_REGISTER_CONTENT_OBSERVER);
	      lListView=(ListView) findViewById(R.id.Tp1_monPanier_listView);
	      lListView.setAdapter(_lAdapter);
	    
	}
	public boolean onCreateOptionsMenu(Menu menu)
	{
		menu.add(0, 100, 0, "Mettre a jour");
		
		return super.onCreateOptionsMenu(menu);
	}
	public boolean onOptionsItemSelected(MenuItem item)
	{
		switch (item.getItemId())
		{
		case 100:
			
			break;

		default:
			break;
		}
		
		return super.onOptionsItemSelected(item);
	}

	@Override
	public void onClick(View v) 
	{

		switch (v.getId())
		{
		case R.id.Tp1_monPanier_button_commander:
			
			DialogCommander();
			break;
        case R.id.Tp1_monPanier_button_precedent:
			
        	Mon_panier.this.finish();
			break;	

		default:
			break;
		}
	}
	
	public void DialogCommander()
	{
		AlertDialog.Builder lBuilder = new AlertDialog.Builder(null);
		lBuilder.setTitle("Commande");
		lBuilder.setMessage("Etes vous sur de vouloir commander l'article");
		lBuilder.setNegativeButton("Annuler", null);
		lBuilder.setPositiveButton("Confirmer", null);
		lBuilder.show();
		}
	
	
}
